home *** CD-ROM | disk | FTP | other *** search
/ Belgian Amiga Club - ADF Collection / BS1 part 26.zip / BS1 part 26 / The Director Toolkit v1.0.adf / Programs / SineTable / docs < prev    next >
Text File  |  1987-02-25  |  3KB  |  80 lines

  1.  
  2. |c7|f2|t1Pie Chart and Sine Table|c3|f1|t0
  3.  
  4. The examples in this directory demonstrate the use of integer based
  5. sine and cosine functions.  There are two demos, a simple routine to
  6. graph the sine and cosine functions on the screen, and a pie chart
  7. example that uses sine and cosine to determine where the pie wedges
  8. lie.|r1
  9.  
  10. The SineCosDemo script demonstrates the basic setup of the sine table
  11. and the basic use.  Since the Director only supports integer arithmetic
  12. and sine values range between |c7+1|c3 and |c7-1|c3, the sine values are 
  13. scaled |c7x10000|c3 providing |c74|c3 significant digits.  You must 
  14. remember when using
  15. the sine values that they are multiplied by |c710000|c3|-.|r1  
  16. |e
  17.  
  18. To use the sine cosine routines, set the variable |c7"deg"|c3 equal to the
  19. value you wish to find the sine or cosine of in degrees.  Then do
  20. a |c7GOSUB 5000|c3 for the sine, or |c7GOSUB 5010|c3 for the cosine.  The 
  21. sine will be returned in the variable |c7sin|c3 and cosine in the variable 
  22. |c7cos|c3|-.|r1
  23.  
  24. You will generally
  25. achieve the best accuracy when using these routines if you do your
  26. multiplies first, then your divides.  This preserves digits of accuracy
  27. longer through your calculations.  
  28. |e
  29.  
  30. For example, if you want to determine
  31. |c7200*sin(x)|c3|-, if you compute it like this:|r1
  32.  
  33. |c7|+8deg=x|r1
  34. |+8gosub 5000  :rem  get the sine|r1
  35. |+8ans=(200*sin)/10000    :rem  multiply before dividing|c3|r1
  36.  
  37. Clearly, if you were to divide by |c710000|c3 first, you would reduce your
  38. sin value to either |c7-1, 0, or 1|c3 losing all precision in your 
  39. calculation.
  40. |e
  41.  
  42. This rule of multiplication first holds through most related calculations,
  43. and you can minimize any truncation errors by rounding like this:|r1
  44.  
  45. |c7|+8ans=(200*sin+5000)/10000|c3|r1
  46.  
  47. To round, add 1/2 of your divisor to the numerator in the division.|r1
  48. |e
  49.  
  50. The Pie Chart demo uses the sine and cosine routines to locate the
  51. various positions of the pie wedges.  The |c7360|c3 degrees of a circle
  52. can be defined graphically as:|r1
  53.  
  54. |c7|+8x = xcenter+sin(deg)*radius|r1
  55. |+8y = ycenter+cos(deg)*radius|c3|r1
  56.  
  57. in mathematical terms.  The Director version of the above calculation
  58. is:|r1
  59.  
  60. |c7|+4deg = 0     :rem  set this to desired degree point on the circle.|r1
  61. |+4gosub 5000|r1
  62. |+4gosub 5010|r1
  63. |+4x = xcenter+(sin*radius+5000)/10000|r1
  64. |+4y = ycenter+(cos*radius+5000)/10000|c3|r1
  65. |e
  66. And, due to the fact that in the Amiga's coordinate system, the |c7Y|c3
  67. coordinate
  68. is inverted (larger |c7Y|c3 goes down instead of up), you can flip the 
  69. |c7Y|c3 axis like this:|r1
  70.  
  71. |c7|+8y = ycenter-(cos*radius+5000)/10000|c3|r1
  72.  
  73. This gives you |c70|c3 degrees on the circle at the top of the circle 
  74. (instead of the bottom).|r1
  75.  
  76. The Pie Chart demo is designed so that you can easily change the size
  77. and center position of the pie chart, and insert your own data and
  78. labelling.  It can be adapted as a general purpose pie chart generator
  79. if desired.
  80.